/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tthdhm.truyvetduongdi.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 *
 * @author BPT
 */
public class Utils {
    private static Utils instance;

    private Utils() {
    }

    public static Utils getInstance() {
        if (instance == null) {
            instance = new Utils();
        }
        return instance;
    }
    
    public String getNowDate(String pattern){
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(cal.getTime());
    }
    
    public Date getDate(){
        java.util.Date utilDate = new java.util.Date();
        return new java.sql.Date(utilDate.getTime());
    }
    
    /**
     * @param strHash
     *            the string give for hash
     * @return the hash value hex
     */
    public String doHashString(String strHash) {
        String result = Constants.BLANK_VALUE;
        try {
            MessageDigest md = MessageDigest.getInstance(Constants.HASH_FUNCTION);
            md.update(strHash.getBytes());
            BigInteger bint = new BigInteger(1, md.digest());
            result = bint.toString(16);
        } catch (NoSuchAlgorithmException ex) {
            return null;
        }
        return result;
    }
}
